package org.zyl.util.image;

import java.util.Date;

import org.zyl.util.time.DateTimeUtils;

/**
 * 图片工具类 
 * @author yzzhouyalei@foxmail.com
 * @time 2017-04-14 15:26:50
 */
public class ImageUtil {
	public static String getImageType(String fileName){
		if (fileName.endsWith(".jpg")||fileName.endsWith(".JPG")) {
			return "jpeg";
		}
		
		if (fileName.endsWith(".png")||fileName.endsWith(".PNG")) {
			return "png";
		}
		
		return "png";
	}
	
	public static String getRandomImageName(String fileName){
		String endPrefix = fileName.substring(fileName.lastIndexOf("."));
		
		String temp = DateTimeUtils.formatDateToString(DateTimeUtils.pattern_yyyyMMddHHmmssSSS, new Date());
		return temp+((int)(Math.random()*100000))+endPrefix;
	}
	
	public static String getFilePathByDate(){
		return DateTimeUtils.formatDateToString(DateTimeUtils.pattern_yyyy_MM_dd, new Date()).replaceAll("-", "/");
	}
}